/*=============== THEN ADDS CENSUS DIVISION & TIME TREND ====================*/


local  dem i.race##i.post2002 i.marst i.famsize i.nchild i.educ i.hispan##i.post2002 i.sex i.nchild##i.pre1988  i.race#i.pre1988
* local  dem i.dem_race##i.post2002  i.dem_race#i.pre1988 i.dem_married i.dem_famsize ///
* i.dem_nchild i.dem_nchild##i.pre1988 i.dem_educ i.dem_female i.dem_hisp##i.post2002

local rhs age* 

local  a1 year i.state_fips `dem'
local  a2 year i.state_fips `dem' strecdums2
local  a3 year i.state_fips `dem' c.year##i.state_fips
local  a4 year i.state_fips `dem' i.year#i.division
local  a5 year i.state_fips `dem' strecdums2 c.year##i.state_fips i.year#i.division


local primary

local j .5
local thresholdlist 1 
local d 1
local j 1
local spec 3
foreach d of numlist 1 {
forvalues spec = 1/4 {
  foreach j of numlist `thresholdlist' {

  use "${data1}march_regready_1984.dta", clear
  
  cap drop strecdums2
  cap drop recdums2
  recode year 2008=1 2009=2 2010=3 nonmissing=0, g(recdums2)
  egen strecdums2 = group(recdums2 state_fips)

  cap drop under

  replace eitc = eitc*eitc_ref
  replace contpov = contpov2
  gen under = contpov < `j'
  local q = `j' * 100
  di "Poverty threshold `q'"
  sum under if demgroup`d'==1
  reghdfe under lnMW `rhs'  [pw=wtsupp] if demgroup`d'==1 , a(`a`spec'') cluster(state_fips)
  est save "${est}ster/84/MW1_`q'_dem`d'_s`spec'_spatial_var", replace

  reghdfe under  lnMW lnMWL1 lnMWL2 lnMWL3 `rhs'  [pw=wtsupp] if demgroup`d'==1 , a(`a`spec'') cluster(state_fips)
  est save "${est}ster/84/MW2_`q'_dem`d'_s`spec'_spatial_var", replace
    * di `spec'
  }

  }


 
}
